package leetcode.editor.week.week312;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

// 6188. 按身高排序
// https://leetcode.cn/problems/sort-the-people/
public class Solution6188 {
    public String[] sortPeople(String[] names, int[] heights) {
        int n = heights.length;
        Map<Integer, Integer> map = new HashMap<>();
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++) {
            map.put(heights[i], i);
            arr[i] = heights[i];
        }

        Arrays.sort(arr, (o1, o2) -> o2 - o1);

        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = names[map.get(arr[i])];
        }

        return res;
    }
}
